//
//  YKOrderDataViewController.m
//  YunKang
//
//  Created by leoking870 on 2017/10/5.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKOrderDataViewController.h"
#import "YKDataHeaderView.h"

#import "YKClientListHeaderView.h"
#import "YKOrderDataItem.h"
@interface YKOrderDataViewController ()
@property (nonatomic, strong) NSString *startTime;
@property (nonatomic, strong) NSString *endTime;
@end

@implementation YKOrderDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"订单详情";
    self.view.backgroundColor = [UIColor whiteColor];
    
    @weakify(self)
    YKDataHeaderView *headerView = [[YKDataHeaderView alloc]initWithType:YKDataHeaderViewTypeYearMonthDay];
    headerView.dateChangeBlock = ^(NSString *start, NSString *end) {
        self_weak_.startTime = start;
        self_weak_.endTime = end;
        [self_weak_ startLoadData];
    };
    [self.view addSubview:headerView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.top.equalTo(self.view.mas_top);
    }];
    
    YKClientListHeaderView* listHeaderView = [[YKClientListHeaderView alloc]initWithTitles:@[@"订单编号",@"客户名称",@"业务员",@"订单金额"] weights:@[@1,@2,@1,@1]];
    listHeaderView.textFont = [UIFont systemFontOfSize:16];
    [self.view addSubview:listHeaderView];
    [listHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.top.equalTo(headerView.mas_bottom);
    }];
    listHeaderView.backgroundColor = [UIColor tf_colorWithHexString:@"#1EADFC"];
    
    listHeaderView.textFont = [UIFont systemFontOfSize:16];
    
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.trailing.equalTo(self.view);
        make.top.equalTo(listHeaderView.mas_bottom);
    }];
    
    self.tableView.tableFooterView = [UIView new];
    
#pragma mark - MOCK
//    TFTableViewSection* section = [TFTableViewSection section];
//    section.headerHeight = .1f;
//    section.footerHeight = .1f;
//    @weakify(self)
//    for (int i = 0; i < 10; ++i) {
//        YKOrderDataItem* item = [YKOrderDataItem item];
//        [section addItem:item];
//        item.hideSeparator = YES;
//        
//        item.selectionHandler = ^(__kindof TFTableViewItem *item, NSIndexPath *indexPath) {
//            
//        };
//    }
    self.dataSource.totalPageKey = @"page.totalpage";
    self.dataSource.currentPageKey = @"curpage";
    [self startLoadData];
    
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.dataSource.manager.sections.count > 0) {
        [self startLoadDataSilently];
    }
}

- (NSDictionary *)pageViewControllerParameters {
    return @{
             kTFPageViewControllerItemClass: [YKOrderDataItem class],
             kTFPageViewControllerModelClass:[YKOrderDataModel class],
             kTFPageViewControllerRequestURL:@"datamanager/searchOrderDataList.htm",
             kTFPageViewControllerDataKeyPath:@"list",
             kTFPageViewControllerRequestParameter:@{@"startTime":self.startTime?:@"", @"endTime":self.endTime?:@""}
             };
}

@end
